if ($('.clock').text() == '') {
    $('.clock').text('0000-00-00' + "\xa0" + '00:00:00')
}
setInterval(function startTime() {
    var today = new Date()
    var y = today.getFullYear()
    var mon = today.getMonth() + 1
    var d = today.getDate()
    var h = today.getHours()
    var m = today.getMinutes()
    var s = today.getSeconds()
    // mon < 10 ? mon ='0'+ mon:
    mon = checkTime(mon)
    d = checkTime(d)
    h = checkTime(h)
    m = checkTime(m)
    s = checkTime(s)
    $('.clock').text(y + "-" + mon + "-" + d + "\xa0" + h + ":" + m + ":" + s);
}, 1000);

function checkTime(i) {
    if (i < 10) {
        i = '0' + i
    }
    return i
}
; (function (win) {
    var tid;

    function refreshRem() {
        let designSize = 1920; // 设计图尺寸
        let html = document.documentElement;
        let wW = html.clientWidth;// 窗口宽度
        let rem = wW * 16 / designSize;
        document.documentElement.style.fontSize = rem + 'px';
    }

    win.addEventListener('resize', function () {
        clearTimeout(tid);
        tid = setTimeout(refreshRem, 30);
    }, false);
    win.addEventListener('pageshow', function (e) {
        if (e.persisted) {
            clearTimeout(tid);
            tid = setTimeout(refreshRem, 300);
        }
    }, false);

    refreshRem();

})(window);


//========================================================================
; (function ($, window, document, undefined) {

    //================================== 表格 ===========================================
    //定义插件的标准姿势：1.构造函数 2.成员定义 3.注册插件
    //1.定义组件的构造函数
    var PumpTable = function (parent, opt) {

        const tpl =
            `<div class="bdz-table-raw">
                <div class="bdz-table-col label">N/A</div>
                <div class="bdz-table-col building">N/A</div>
                <div class="bdz-table-col area">N/A</div>
                <div class="bdz-table-col sensor">N/A</div>
                <div class="bdz-table-col liquid-level">N/A</div>
                <div class="bdz-table-col pump1-status">N/A</div>
                <div class="bdz-table-col pump1-control-status">N/A</div>
                <div class="bdz-table-col pump2-status">N/A</div>
                <div class="bdz-table-col pump2-control-status">N/A</div>
                <div class="bdz-table-col pump3-status">N/A</div>
                <div class="bdz-table-col pump3-control-status">N/A</div>
                <div class="bdz-table-col pump4-status">N/A</div>
                <div class="bdz-table-col pump4-control-status">N/A</div>
                <div class="bdz-table-col pump5-status">N/A</div>
                <div class="bdz-table-col pump5-control-status">N/A</div>
                <div class="bdz-table-col pump6-status">N/A</div>
                <div class="bdz-table-col pump6-control-status">N/A</div>
                <div class="bdz-table-col low-water-level-alarm">N/A</div>
                <div class="bdz-table-col pump-stopping-water-level">N/A</div>
                <div class="bdz-table-col pump1-starting-value">N/A</div>
                <div class="bdz-table-col pump2-starting-value">N/A</div>
                <div class="bdz-table-col high-water-level-alarm">N/A</div>
            </div>`;
        this.$parent = parent;
        this.$element = $(tpl);
        this.$parent.append(this.$element);
        this.defaults = {
            'top': 0,
            'left': 0
        };
        var that = this;
        //叠加默认选项和传入选项到一个新的对象，防止修改默认选项
        this.options = $.extend({}, this.defaults, opt);
        // this.$element.find('.label').text(this.options.name);
        // this.$element.attr('id', 'bdz-table-raw' + this.options.name);//赋予独特的id
        // this.$element.css('top', this.options.top);
        // this.$element.css('left', this.options.left);
        // this.$element.find('.bdz-table-col').attr('title',$(this).text());

    }
    //2.定义组件的成员变量和方法
    PumpTable.prototype = {
        /**
         * 根据数据更新组件显示
         * @param {组件数据} data
         */
        showCircuitInfo(data) {
            this.$element.find('.circuit-info').text(data['LoadName'].value);
        },
        update(data) {
            console.log(data);

            this.$element.find('.label').text(data['id']);
            this.$element.find('.building').text(data['tunnel']);
            this.$element.find('.area').text(data['area']);
            this.$element.find('.sensor').text('1#传感器');
            if(data['levelValue']!=null){
                this.$element.find('.liquid-level').text(data['levelValue']);
            }else{
                this.$element.find('.liquid-level').text('-');
            }

            //状态
            for(let i =1;i<=6;i++){
                let pumpStateValue
                if(data['pumpStateValue'+i]==0&&data['pumpStateValue'+i]!=null){
                    pumpStateValue='停止'
                }else if(data['pumpStateValue'+i]==1&data['pumpStateValue'+i]!=null){
                    pumpStateValue='运行'
                    this.$element.find('.pump'+i+'-status').css('color','aqua')
                }else{
                    pumpStateValue='-'
                }
                this.$element.find('.pump'+i+'-status').text(pumpStateValue);
            }
            //控制
            for(let i =1;i<=6;i++){
                let pumpModeValue
                if(data['pumpModeValue'+i]==0&&data['pumpModeValue'+i]!=null){
                    pumpModeValue='手动'
                }else if(data['pumpModeValue'+i]==1&data['pumpModeValue'+i]!=null){
                    pumpModeValue='自动'
                    this.$element.find('.pump'+i+'-control-status').css('color','aqua')
                }else{
                    pumpModeValue='-'
                }
                this.$element.find('.pump'+i+'-control-status').text(pumpModeValue);
            }
            //故障
            for(let i =1;i<=6;i++){
                //故障效果测试 if(data['pumpError'+i]==0&&data['pumpError'+i]!=null&&data['pumpModeValue'+i]==0){
                if(data['pumpError'+i]==1&&data['pumpError'+i]!=null){
                    pumpError='自动'
                    this.$element.find('.pump'+i+'-status').css('color','red')
                    this.$element.find('.pump'+i+'-status').text('故障');
                    this.$element.css('background-color','rgba(255,0,0,0.2)')
                }
                console.log('故障',data['pumpError'+i]);
            }
           
            this.$element.find('.low-water-level-alarm').text(data['lowLevel']);
            this.$element.find('.pump-stopping-water-level').text(data['stopLevel']);
            this.$element.find('.pump1-starting-value').text(data['startLevel1']);
            this.$element.find('.pump2-starting-value').text(data['startLevel2']);
            this.$element.find('.high-water-level-alarm').text(data['highLevel']);

            this.$element.find('.bdz-table-col').each(function () {
                // 获取元素自身文本内容
                const elementText = $(this).text();
                // 将文本设置为 title 属性
                $(this).attr("title", elementText);
            });
            /*var uab = data['Uab'].value;
            var ubc = data['Ubc'].value;
            var uca = data['Uca'].value;
            if (uab != null || ubc != null || uca != null) {

            } else {

            }*/
        },

    }
    //3.注册组件为jquery插件
    $.fn.pumpTable = function (options) {
        var plugin = new PumpTable(this, options);
        return plugin;//返回组件对象
    }

})(jQuery, window, document);
